package server;

import java.util.LinkedList;

public class Document {
	String doctor;
	String nurse;
	String ward;
	String patient;
	LinkedList<String> notes;
	
	public Document (String doctor, String nurse, String ward, String patient){
		this.doctor = doctor;
		this.nurse = nurse;
		this.ward = ward;
		this.patient = patient;
		notes = new LinkedList<String>();
	}
	
	public void addNotes(String note) {
		notes.add(note);
	}
	
	public boolean hasReadAccess(String requester, String wardReq){
		String[] titleName = requester.split(" ");
		if (requester.equals("Government Agency")){
			return true;
		} else if ((titleName[0].equals("Doctor") 
				|| titleName[0].equals("Nurse")) 
				&& wardReq.equals(ward)){
			return true;
		} else if (requester.equals(doctor) 
				|| requester.equals(nurse)
				|| requester.equals(patient)) {
			return true;
		} 
		return false;
	}
	
	public boolean hasWriteAccess(String requester){
		if (requester.equals(doctor) 
			|| requester.equals(nurse)) {
			return true;
		} 
		return false;
	}

	@Override
	public String toString() {
		String ans = "";
		ans += "Doctor: " + doctor + "\n";
		ans += "Nurse: " + nurse + "\n";
		ans += "Ward: " + ward + "\n";
		ans += "Patient: " + patient + "\n";
		ans += "Notes:\n";
		for (String s : notes) {
			ans += s + "\n";
		}
		return ans;
	}

}
